#include <iostream>
#include "SmartPointer.h"
#include "Exception.h"
#include "Object.h"

using namespace std;
using namespace DTLib;


class Test : public Object
{
public:
    int i;
    int j;

    Test()
    {
        cout << "Test()" << endl;
    }

    ~Test()
    {
        cout << "~Test()" << endl;
    }
};

class Child : public Test
{
public:
    int k;
};

int main()
{
    SmartPointer<Test> sp = new Test();

    SmartPointer<Test> nsp;

    nsp = sp;

    cout << sp.isNull() << endl;
    cout << nsp.isNull() << endl;
    cout << "nsp = " << nsp.get() << endl;

    try
    {
       THROW_EXCEPTION(ArithmeticException, "test");
    }
    catch(const ArithmeticException& e)
    {
        cout << "catch(const ArithmeticException& e)" << endl;
        cout << e.message() << endl;
        cout << e.location() << endl;
    }
    catch(const Exception& e)
    {
        cout << "catch(const Exception& e)" << endl;
        cout << e.message() << endl;
        cout << e.location() << endl;
    }

    Object* obj1 = new Test();
    Object* obj2 = new Child();

    cout << "obj1 = " << obj1 << endl;
    cout << "obj2 = " << obj2 << endl;

    delete obj1;
    delete obj2;

    return 0;
}
